package com.ruoyi.cpsp.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.cpsp.mapper.RegulationDetailMapper;
import com.ruoyi.cpsp.domain.RegulationDetail;
import com.ruoyi.cpsp.service.RegulationDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author neu.xiaojiacheng
 * @version 1.0
 * @date 2022/2/24 15:02
 */
@Service
@Transactional
public class RegulationDetailServiceImpl implements RegulationDetailService {

    @Autowired
    private RegulationDetailMapper regulationDetailMapper;



    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean submitAllInfo(RegulationDetail regulationDetail) {
        int flag = regulationDetailMapper.insert(regulationDetail);
        if (flag > 0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Map<String, Object> getByTypeId(int pageSize, int currentPage, int typeId) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(currentPage, pageSize);
        List<String> list = regulationDetailMapper.selectByTypeId(typeId);
        PageInfo pageRecord = new PageInfo(list);
        long sum = pageRecord.getTotal();
        list = pageRecord.getList();
        map.put("records",list);
        map.put("sum",sum);
        return map;
    }

    @Override
    public Map<String, Object> getByTypeIdAndDescribe(int pageSize, int currentPage, int typeId,String describe) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(currentPage, pageSize);
        List<RegulationDetail> list = regulationDetailMapper.selectByTypeIdAndDescribe(typeId,describe);
        PageInfo pageRecord = new PageInfo(list);
        long sum = pageRecord.getTotal();
        list = pageRecord.getList();
        map.put("records",list);
        map.put("sum",sum);
        return map;
    }

    @Override
    public int delete(int id) {
        return regulationDetailMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(RegulationDetail record) {
        return regulationDetailMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public RegulationDetail selectByPrimaryKey(Integer id) {
        return regulationDetailMapper.selectByPrimaryKey(id);
    }
}
